﻿// Decompiled with JetBrains decompiler
// Type: SP1.TextElements
// Assembly: SP1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 4A78F1E7-7FD5-407C-8917-5F99ECC43C34
// Assembly location: C:\Users\KasimGulcan\Desktop\Project\DynaCAD\bin\Debug\SP1.dll

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Xml;

namespace SP1
{
  public static class TextElements
  {
    public static Border TextCreator(XmlNode xn)
    {
      FontFamilyConverter fontFamilyConverter = new FontFamilyConverter();
      bool flag = false;
      Border B = new Border();
      TextBlock x = new TextBlock();
      foreach (XmlAttribute xmlAttribute in (XmlNamedNodeMap) xn.Attributes)
      {
        if (xmlAttribute.Value.Replace(" ", "") != "none")
        {
          switch (xmlAttribute.Name.Replace(" ", ""))
          {
            case "x":
              Canvas.SetLeft((UIElement) B, AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value));
              continue;
            case "y":
              Canvas.SetTop((UIElement) B, AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value));
              continue;
            case "fill":
              x.Foreground = AtributeValueLibrary.GetBrush(xmlAttribute.Value);
              flag = true;
              continue;
            case "stroke":
              B.BorderBrush = AtributeValueLibrary.GetBrush(xmlAttribute.Value);
              flag = true;
              continue;
            case "font-size":
              x.FontSize = AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value);
              flag = true;
              continue;
            case "letter-spacing":
              x.FontFamily.LineSpacing = AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value);
              flag = true;
              continue;
            case "kerning":
              x.FontFamily.LineSpacing = AtributeValueLibrary.DoubleConvertor(xmlAttribute.Value);
              flag = true;
              continue;
            case "word-spacing":
              Console.WriteLine("WordSpacing");
              flag = true;
              continue;
            case "transform":
              TransFormLibrary.TransForm((UIElement) B, xmlAttribute.Value);
              continue;
            case "writing-mode":
              Console.WriteLine("writing-mode: tb etc");
              flag = true;
              continue;
            case "glyph-orientation-vertical":
              Console.WriteLine("glyph-orientation");
              flag = true;
              continue;
            case "direction":
              Console.WriteLine("direction: rtl");
              flag = true;
              continue;
            case "font-family":
              try
              {
                x.FontFamily = (FontFamily) fontFamilyConverter.ConvertFromString(xmlAttribute.Value);
              }
              catch
              {
                Console.WriteLine("FontFamily Could not be Converted" + xmlAttribute.Value);
              }
              flag = true;
              continue;
            case "text-decoration":
              Console.WriteLine("text-decoration");
              flag = true;
              continue;
            case "texlenght":
              Console.WriteLine("textlenght");
              flag = true;
              continue;
            case "lenghtAdjust":
              Console.WriteLine("LenghtAdjust");
              flag = true;
              continue;
            case "text-anchor":
              x.TextAlignment = AtributeValueLibrary.TextAlighmentConvertor(xmlAttribute.Value);
              flag = true;
              continue;
            case "style":
              AtributeValueLibrary.StyleAttribute(ref x, ref B, xmlAttribute.Value);
              flag = true;
              continue;
            case "filter":
              x.Effect = AtributeValueLibrary.FilterConvertor(xmlAttribute.Value);
              continue;
            default:
              continue;
          }
        }
      }
      if (!flag)
        AtributeValueLibrary.StyleAttribute(ref x, ref B, DefinitionElement.style);
      x.Text = xn.InnerText;
      B.Child = (UIElement) x;
      return B;
    }
  }
}
